﻿using System;
using System.Collections.Generic;
using System.Text;
using XiaoGang.Soft.XGWMS.COM;
using XiaoGang.Soft.XGWMS.MODEL;
using XiaoGang.Soft.XGWMS.DAL_SQL;

namespace XiaoGang.Soft.XGWMS.BLL
{
    public class BLL_M008_STOREROOM
    {
        XGWMS.DAL_SQL.DAL_M008_STOREROOM dal_M008_STOREROOM = new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_M008_STOREROOM();
        private readonly XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess dal_ComProcess = new XiaoGang.Soft.XGWMS.DAL_SQL.DAL_ComProcess();
        private readonly XiaoGang.Soft.XGWMS.BLL.BLL_ComProcess bll_ComProcess = new BLL_ComProcess();

        /// <summary>
        /// <p><b>方法名称</b>StorageRoomDeleteCheck</p>	
        /// <p><b>概要説明  :</b>检测仓库有没有被使用</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/17</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="string" name="strStorageRoomID">仓库编码</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue StorageRoomDeleteCheck(string strStorageRoomID)
        {
            return dal_M008_STOREROOM.StoreRoomDeleteCheck(strStorageRoomID);
        }

        /// <summary>
        /// <p><b>方法名称</b>CheckName</p>	
        /// <p><b>概要説明  :</b>仓库名称的检索</p>
        /// <p><b>作成者    :</b>万岗</p>	
        /// <p><b>作成日    :</b>2008/09/17</p>	
        /// <p><b>修改历史  :</b></p>	
        /// </summary>	
        /// <param type="class" name="model">仓库名称</param>
        /// <returns type = "ReturnValue"></returns>
        public ReturnValue CheckName(string StoreRoomName)
        {
            return dal_M008_STOREROOM.CheckName(StoreRoomName);
        }

        /// <summary>
        /// <p><b>方法名称</b>InitComBoxProcess</p>
        /// <p><b>概要説明  :</b>仓库管理者的初始化</p>
        /// <p><b>作成者	:</b>万岗</p>
        /// <p><b>作成日	:</b>2008/09/01</p>
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <returns type="ReturnValue">仓库管理者信息表</returns>
        public ReturnValue InitComBoxProcess()
        {
            return dal_M008_STOREROOM.Init_Combox();
        }

        /// <summary>	
        /// <p><b>方法名称</b>GetSingleDataProcess</p>	
        /// <p><b>概要説明  :</b>取得单条仓库信息</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/01</p>	
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type="MOD_M008_STOREROOM" param="model">仓库编号</param>
        /// <returns type="ReturnValue">单条仓库信息</returns>
        public ReturnValue GetSingleDataProcess(string StoreRoomID)
        {
            return dal_M008_STOREROOM.GetSingleData(StoreRoomID);
        }

        /// <summary>	
        /// <p><b>方法名称</b>SearchProcess</p>	
        /// <p><b>概要説明  :</b>仓库信息的检索</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/01</p>	
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type="MOD_M008_STOREROOM" param="model">检索条件</param>
        /// <returns type="ReturnValue">检索结果表</returns>
        public ReturnValue SearchProcess(MODEL.MOD_M008_STOREROOM model)
        {
            return dal_M008_STOREROOM.SearchProcess(model);
        }

        /// <summary>	
        /// <p><b>方法名称</b>InsertProcess</p>	
        /// <p><b>概要説明  :</b>仓库信息的插入</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/01</p>	
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type="calss" param="model">仓库信息</param>
        /// <returns type="ReturnValue">执行结果信息</returns>
        public ReturnValue AddOrUpdateStoreRoom(MODEL.MOD_M008_STOREROOM model)
        {
            ReturnValue returnValue;

            if (model.STOREROOM_ID != "")
            {
                //更新
                //首先检查不同ID但同名称仓库
                returnValue = dal_M008_STOREROOM.CheckStoreRoomNameWithoutID(model.STOREROOM_ID, model.STOREROOM_NM);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count > 0)
                {
                    return new ReturnValue(false, "W11H01");//本[@]已经存在或已被逻辑删除!
                }
                //检查是否存在该ID的数据
                returnValue = dal_M008_STOREROOM.GetSingleData(model.STOREROOM_ID);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count < 1)
                {
                    return new ReturnValue(false, "W11057");//该数据不存在
                }
                //进行更新
                return dal_M008_STOREROOM.UpdateProcess(model);
            }
            else
            {
                //新添加
                //首先检查名称是否已经存在
                returnValue = dal_M008_STOREROOM.CheckName(model.STOREROOM_NM);
                if (!returnValue.IsSuccess)
                {
                    return returnValue;
                }
                if (returnValue.ResultDataSet.Tables[0].Rows.Count > 0)
                {
                    return new ReturnValue(false, "W11E01");//本[@]已经存在。
                }
                string UniqueNo = string.Empty;
                if (!DAL_ComProcess.GetUniqueNo(model.UPDATER_ID
                    , model.TERMINAL_CD
                    , "03"
                    , System.DateTime.Now.Year.ToString("####")
                    , out UniqueNo))
                {
                    return new ReturnValue(false, "E11003");//生成业务编号失败
                }
                model.STOREROOM_ID = UniqueNo;
                //进行添加
                return dal_M008_STOREROOM.InsertProcess(model);
            }
        }        

        /// <summary>	
        /// <p><b>方法名称</b>UpdateProcess</p>	
        /// <p><b>概要説明  :</b>仓库信息的理论删除</p>	
        /// <p><b>作成者	:</b>万岗</p>	
        /// <p><b>作成日	:</b>2008/09/02</p>	
        /// <p><b>修改历史  :</b></p>
        /// </summary>
        /// <param type="MOD_M008_STOREROOM" param="model">仓库编号</param>
        /// <returns type="ReturnValue">执行结果信息</returns>
        public string DeleteProcess(MODEL.MOD_M008_STOREROOM model)
        {
            ReturnValue returnValue;
            returnValue = dal_M008_STOREROOM.LogicDeleteProcess(model);

            if (returnValue.IsSuccess == false)
            {
                return returnValue.ErrorID;
            }
            return "0";
        }

        /// <summary>
        /// 物理删除仓库
        /// </summary>
        /// <param name="StoreRoomID"></param>
        /// <returns></returns>
        public ReturnValue PhysicalDeleteProcess(string StoreRoomID)
        {
            return dal_M008_STOREROOM.PhysicalDeleteProcess(StoreRoomID);
        }

        /// <summary>
        /// 检查仓库是否正在使用
        /// </summary>
        /// <param name="strGoodsGroupID"></param>
        /// <returns></returns>
        public ReturnValue IsStoreRoomUsed(string StoreRoomID)
        {
            return dal_M008_STOREROOM.StoreRoomDeleteCheck(StoreRoomID);
        }

        /// <summary>
        /// 获取除本ID的同名仓库名称
        /// </summary>
        /// <param name="StoreRoomID"></param>
        /// <param name="StoreRoomName"></param>
        /// <returns></returns>
        public ReturnValue CheckStoreRoomNameWithoutID(string StoreRoomID, string StoreRoomName)
        {
            return dal_M008_STOREROOM.CheckStoreRoomNameWithoutID(StoreRoomID, StoreRoomName);
        }
    }
}
